﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCenter.PluginFramework
{
    public abstract class PlugInHostBase : IPlugInHost
    {
        private PlugInCollection _extensions = null;

        public PlugInHostBase()
        {
            _extensions = new PlugInCollection();
        }

        public abstract void Load();

        public abstract void UnLoad();

        public PlugInCollection Extensions
        {
            get { return _extensions; }
            set { _extensions = value; }
        }

        public event EventHandler<EventArgs> PreLoad;

        public event EventHandler<EventArgs> LoadComplete;

        public event EventHandler<EventArgs> PreUnLoad;

        public event EventHandler<EventArgs> UnLoadComplete;

        public event EventHandler<EventArgs> LoadFailed;

        protected virtual void OnPreLoad(EventArgs e)
        {
            EventHandler<EventArgs> tempHandler = PreLoad;
            if (tempHandler != null)
            {
                tempHandler(this, e);
            }
        }

        protected virtual void OnLoadComplete(EventArgs e)
        {
            EventHandler<EventArgs> tempHandler = LoadComplete;
            if (tempHandler != null)
            {
                tempHandler(this, e);
            }
        }

        protected virtual void OnPreUnLoad(EventArgs e)
        {
            EventHandler<EventArgs> tempHandler = PreUnLoad;
            if (tempHandler != null)
            {
                tempHandler(this, e);
            }
        }

        protected virtual void OnUnLoadComplete(EventArgs e)
        {
            EventHandler<EventArgs> tempHandler = UnLoadComplete;
            if (tempHandler != null)
            {
                tempHandler(this, e);
            }
        }

        protected virtual void OnLoadFailed(EventArgs e)
        {
            EventHandler<EventArgs> tempHandler = LoadFailed;
            if (tempHandler != null)
            {
                tempHandler(this, e);
            }
        }
    }
}
